//
//  BaseViewController.m
//  CapriceMusic
//
//  Created by 蒋恩浩 on 16/1/6.
//  Copyright © 2016年 MYX. All rights reserved.
//

#import "BaseViewController.h"
#import "SearchViewController.h"
#import "AppDelegate.h"
#import "ChannelViewController.h"
#import "HomePageViewController.h"
#import "DownLoadViewController.h"
#import "FavoritesViewController.h"

#import "VRankViewController.h"

//#import "FavoritesViewController.h"


@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //关闭半透明
    self.navigationController.navigationBar.translucent = NO;
    //设置样式
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    //状态栏字体颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 背景颜色
    self.view.backgroundColor = [UIColor blackColor];

    //左侧按键
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"LeftList"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarDidButton:)];
    //右侧按键
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"RightSearch"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(rightbarDidButton:)];
}

- (void)jump:(NSNotification *)message {
    if ([message.object isEqualToString:@"0"]) {
        [self.navigationController popToRootViewControllerAnimated:NO];
    } else if ([message.object isEqualToString:@"1"]) {
        ChannelViewController *channel = [[ChannelViewController alloc] init];
        [self.navigationController pushViewController:channel animated:NO];
    } else if ([message.object isEqualToString:@"3"]){
        DownLoadViewController *download = [[DownLoadViewController alloc] init];
        [self.navigationController pushViewController:download animated:NO];
    } else if ([message.object isEqualToString:@"2"]) {
        VRankViewController *vRank = [[VRankViewController alloc] init];
        [self.navigationController pushViewController:vRank animated:NO];
    } else if ([message.object isEqualToString:@"5"]) {
        FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
        [self.navigationController pushViewController:favorites animated:NO];
    } else {
        MusicViewController *music = [[MusicViewController alloc] init];
        [self.navigationController pushViewController:music animated:NO];
    }
   

}

//左侧按键
- (void)leftBarDidButton:(UIBarButtonItem *)sender {
    NSLog(@"左侧按键");
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    
    if (tempAppDelegate.LeftSlideVC.closed)
    {
        [tempAppDelegate.LeftSlideVC openLeftView];
    }
    else
    {
        [tempAppDelegate.LeftSlideVC closeLeftView];
    }
}
//右侧按键
- (void)rightbarDidButton:(UIBarButtonItem *)sender {
    NSLog(@"右侧按键");
    SearchViewController *searchVC = [[SearchViewController alloc] init];
    
    [self.navigationController pushViewController:searchVC animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:NO];
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [tempAppDelegate.LeftSlideVC setPanEnabled:YES];
    
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(jump:) name:@"jumpTo" object:nil];
    
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
//    self.tabBarController.tabBar.frame = CGRectMake(0, self.view.bounds.size.height + 120, self.view.bounds.size.width, 44);
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
//    [UIView animateWithDuration:1 animations:^{
//        //        设置动画重复的次数
//        [UIView setAnimationRepeatCount:1];
//        //        动画延时几秒
//        [UIView setAnimationDelay:0];
//        self.tabBarController.tabBar.frame = CGRectMake(0, self.view.bounds.size.height  + 64, self.view.bounds.size.width, 44);
//        
//    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
